<?php

namespace cf\api\user;

require_once dirname(__FILE__).'/../user.php';

function login($username, $password, $remember=false)
{
   if (!$username || !$password) {
      throw new \Exception('Specify username and password');
   }
   return \cf\User::login($username, $password, $remember);
}

function logout()
{
	$user = \cf\User::getLoggedIn();
	if ($user) {
		$user->logout();
	}
}



/*
function register($username, $password, $password_verify, $name, $email='')
{
	$username = trim($username);
	$password = trim($password);
	$name = trim($name);
	$email = trim($email);
	
	if (strlen($username) < 5 || strlen($username) > 16 ||
		strlen($password) < 5 ||
		$password != trim($password_verify) ||
		strlen($name) < 3 || strlen($name) > 128 )
	{
		throw new \Exception('Register error');
	}

   if (\squidd\User::exists($username)) {
      throw new \Exception('This username already exists');
   }

   $id = \squidd\User::register($username, $password, $name, $email);

   $user = new \squidd\User($id);

   //create USER PROFILE
   $profileId = \squidd\Item::add(
              'user_profiles', 
              $user->id(), 
              "User '{$user->username()}' profile"
   );

   //login user immediately
   $_SESSION['user'] = $user;

	return $id;
}
*/


?>